<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="${basePath}/public/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${basePath}/public/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<title>接口管理</title>
<#include "lib/lib.html" />
</head>
<body class="pos-r">

<div class="pos-a" style="width:230px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
	 <div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l"> <a href="javascript:;" onclick="interface_add('添加接口信息','${basePath}/intefaces/edit.do','','310')" class="btn btn-primary radius">
		<i class="Hui-iconfont">&#xe600;</i> 添加接口  </a></span>
	 </div>
		<table id="interfaceList" class="table table-border table-bordered table-bg table-hover">
			<tbody>
				<#if interfaceList?? && interfaceList?size gt 0>
					<#list interfaceList as dl >
						<tr class="text-c" >
							<td><a href="javascript:;" onclick="refreshInterfaceList(${dl.id})" >${dl.interfaceName!}</a></td>							
						</tr>
					</#list>
					</#if>
				</tbody>
			
		</table>
</div>
<input type="hidden" name="resourceId" id="resourceId">
	<input type="hidden" name="appId" id="appId" value="${appId!}">

<div id="interfaceDiv" style="margin-left:230px;">

</div>

<script type="text/javascript" src="${basePath}/public/js/dateUtil.js"></script> 
<script type="text/javascript">

$(document).ready(function(){
	//_initInterfaceTree();
	
});

 $('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	                  {sDefaultContent: '',aTargets: [ '_all' ]
	                      }]
	/* "aoColumnDefs": [
	  {"orderable":false,"aTargets":[0,7]}// 制定列不参与排序
	] */
}); 
/*-----提交接口信息------*/
function _submitInterfaceInfo(){
	$("[name='interfaceForm']").submit();
}
function _initInterfaceForm(){
	$("[name='id']").val();
	$.ajax({
		url:'',
		data:'',
		dataType:'json',
		success:function(data){
			$("[name='funName']").val(data.interfaceName);
			$("[name='reqType']").val(data.reqType);
			$("[name='reqUrl']").val(data.reqUrl);
			$("[name='interfaceDesc']").val(data.interfaceDesc);
		}
	});
}
/*----刷新接口信息列表---*/
function refreshInterfaceList(interfaceId){
// 	$.ajax({
// 		url:'${basePath}/intefaces/getInterfaceInfo.do?interfaceId='+interfaceId,
// 		data:'',
// 		dataType:'json',
// 		success:function(data){
// 			var list=data.info;				
// 				var rowStr  =   " <tr>" +
// 								"	<td>"+list.interfaceName+"</td>\n" +
// 								"	<td>"+list.reqType+"</td>\n" +
// 								"	<td>"+list.reqUrl+"</td>\n" +
// 								"	<td>"+list.interfaceDesc+"</td>\n" +
// 								"   <td><a href=\"javascript:;\" onclick=\"interface_update('编辑接口信息','${basePath}/intefaces/edit.do','','310','"+list.id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>"+
// 								" 		<a title=\"删除\" href=\"javascript:;\" onclick=\"interface_delete('"+list.id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>"+
// 								"		<a title=\"接口测试\" href=\"javascript:;\" onclick=\"interface_test('"+list.id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">接口测试</i></a></td>"+
// 									"<td><a title=\"添加参数\"  href=\"javascript:;\" onclick=\"interfaceListTrClickEvent('"+list.id+"')\" class=\"ml-5 btn btn-primary radius\" style=\"text-decoration: none\">添加参数</a></td>"+
// 								" </tr>";	
// 				$("#interfaceList").append(rowStr);
// 		}
// 	});
	var data = {};
	data.interfaceId = interfaceId;
	$.ajax({
		url:'${basePath}/intefaces/getInterfaceInfo.do',
		data:data ,
		dataType:'html',
		success:function(html){
			$("#interfaceDiv").html(html);
		}
	});
}


/*-----刷新请求参数列表------*/
function refreshReqParamList(interfaceId){
 	$.ajax({
 		url:'${basePath}/InterfaceParam/query.do?interfaceId='+interfaceId+'&paramType=1',
 		data:'',
 		dataType:'json',
 		success:function(data){
 			$("#reqParamList tr:gt(0)").remove();
 			var list=data.list;
 			for (var index = 0; index < list.length; index++) {
 				var mill = list[index].createTime;
				var createTime = DateFormat.prototype.format(new Date(mill),'yyyy-MM-dd HH:mm:ss');
 				var rowStr  =   " <tr class=\"text-c va-m\">\n" +
 								"	<td>"+list[index].paramName+"</td>\n" +
								"	<td>"+list[index].paramDesc+"</td>\n" +
 								"	<td>"+list[index].paramProperties+"</td>\n" +
 								"	<td>"+list[index].paramRemark+"</td>\n" +
 								"	<td>"+createTime+"</td>\n" +
								"   <td><a title=\"编辑\" href=\"javascript:;\" onclick=\"reqParam_update('编辑请求参数','${basePath}/InterfaceParam/jumpEditOrAdd.do','','310','"+list[index].id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a> "+
 								" 		<a title=\"删除\" href=\"javascript:;\" onclick=\"reqParam_delete('"+list[index].id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a></td>"+
 								" </tr>";
								
 				$("#reqParamList").find("tbody").append(rowStr); 
 			}
 		}
 	});
	//window.location.href="${basePath}/intefaces/interfaceTest.do?id="+id;
}
/*-----刷新响应参数列表------*/
function refreshRespParamList(interfaceId){
	$.ajax({
		url:'${basePath}/InterfaceParam/query.do?interfaceId='+interfaceId+'&paramType=2',
		data:'',
		dataType:'json',
		success:function(data){
			$("#respParamList tr:gt(0)").remove();
			var list=data.list;
			for (var index = 0; index < list.length; index++) {
				var mill = list[index].createTime;
				var createTime = DateFormat.prototype.format(new Date(mill),'yyyy-MM-dd HH:mm:ss');
				var rowStr  =   " <tr class=\"text-c va-m\">\n" +
				"	<td>"+list[index].paramName+"</td>\n" +
				"	<td>"+list[index].paramDesc+"</td>\n" +
				"	<td>"+list[index].paramProperties+"</td>\n" +
				"	<td>"+list[index].paramRemark+"</td>\n" +
				"	<td>"+createTime+"</td>\n" +
				"   <td><a title=\"编辑\" href=\"javascript:;\" onclick=\"respParam_update('编辑响应参数','${basePath}/InterfaceParam/jumpEditOrAdd.do','','310','"+list[index].id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a> "+
				" 		<a title=\"删除\" href=\"javascript:;\" onclick=\"respParam_delete('"+list[index].id+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a></td>"+
				" </tr>";
				
				$("#respParamList").find("tbody").append(rowStr);
			}
		}
	});
}

function interfaceListTrClickEvent(id){
	//选中的时候切换css样式
	$("#interfaceId").val(id);
	refreshReqParamList(id);
	refreshRespParamList(id);
	$("#reqDiv").show();
	$("#respDiv").show();
}
function interface_add(title,url,w,h){
	url = url+"?appId="+$("#appId").val();
	layer_show(title,url,w,h);
}
function interface_update(title,url,w,h,id){
	url = url+"?id="+id;
	layer_show(title,url,w,h);
}

function reqParam_add(title,url,w,h){
	url = url+"?interfaceId="+$("#interfaceId").val()+"&paramType=1";
	layer_show(title,url,w,h);
}
function reqParam_update(title,url,w,h,id){
	url = url+"?id="+id;
	layer_show(title,url,w,h);
}
function reqParam_delete(id){
	if(confirm("确定删除该请求参数")){
		$.ajax({
			type:'POST',
			url:'${basePath}/InterfaceParam/delete.do?id='+id,
			data:'',
			dataType:'json',
			success:function(data){
				if(data.status=="success"){
					refreshReqParamList($("[name='interfaceId']").val());
				}else{
					alert(data.message);
				}
			}
		});
	}
}

function respParam_add(title,url,w,h){
	url = url+"?interfaceId="+$("#interfaceId").val()+"&paramType=2";
	layer_show(title,url,w,h);
}
function respParam_update(title,url,w,h,id){
	url = url+"?id="+id;
	layer_show(title,url,w,h);
}
function respParam_delete(id){
	if(confirm("确定删除该响应参数")){
		$.ajax({
			type:'POST',
			url:'${basePath}/InterfaceParam/delete.do?id='+id,
			data:'',
			dataType:'json',
			success:function(data){
				if(data.status=="success"){
					refreshRespParamList($("[name='interfaceId']").val());
				}else{
					alert(data.message);
				}
			}
		});
	}
}
function interface_delete(id){
	if(confirm("确认删除接口以及对应的参数信息？")){
		//如果有显示参数列表，当删除的接口为当前显示的参数列表时，隐藏参数列表
		if(id==$("#interfaceId").val()){
			$("#reqDiv").hide();
			$("#respDiv").hide();
		}
		$.ajax({
			type: 'POST',
			url:'${basePath}/intefaces/delete.do?id='+id,
			data:'',
			dataType:'json',
			success:function(data){
				if(data.status=="success"){
					window.location.href="${basePath}/intefaces/getList.do?appId=77";
					/* refreshInterfaceList(); */
				}else{
					alert(data.message);
				}
			}
		});
	}
}
//接口测试
function interface_test(id){
	var url ="${basePath}/intefaces/interfaceTest.do?id="+id;
	layer_show("接口测试", url, 900,800 );
}
</script>
</body>
</html>